objectdef ezvg_Combat inherits Act
{

  ;############################################
  ;##
  ;##  DO NOT FUCK WITH THE FOLLOWING
  ;##
  ;############################################
  
  variable uint nextCheckT
  variable uint meleeFocus
  variable uint lastAssistT
  variable bool inBurn
  variable bool petAttacking
  
  variable bool CommandAssist

  variable uint lastBuffCheckT

  method Initialize()
  {
    This[parent]:Initialize
    This.CommandAssist:Set[FALSE]
  }
  
  method Shutdown()
  {
  }

  method ResetTgt()
  {
    This[parent]:ResetTgt
    This.CommandAssist:Set[FALSE]
  }
  
  method changeNextT(float modT)
  {
    if ${This.nextCheckT}<${Math.Calc[${Script.RunningTime}+(${modT}*1000)]}
      This.nextCheckT:Set[${Math.Calc[${Script.RunningTime}+(${modT}*1000)]}]
  }

  member:bool isReady()
  {
    if ${This.nextCheckT} > ${Script.RunningTime}
      return FALSE
    return TRUE
  }

  method changeTgt(int64 tgtID)
  {
    Pawn[id, ${tgtID}]:Target
    This:changeNextT[0.250]
  }
  
  method ForceAssist()
  {
    ;echo ~~~!!! ForceAssist !!!~~~~
    This.CommandAssist:Set[TRUE]
    if ${Me.DTarget.ID}!=${AssistID}
      This:changeTgt[${AssistID}]
    VGExecute /assist
    This.lastAssistT:Set[${Math.Calc[${Script.RunningTime}+5000]}]
    This:changeNextT[0.250]
  }

  method Assist()
  {
    if ${This.lastAssistT}>${Script.RunningTime}
      return
    else
    {                                              
      if ${Me.DTarget.ID}!=${AssistID}
        This:changeTgt[${AssistID}]
      VGExecute /assist
      This.lastAssistT:Set[${Math.Calc[${Script.RunningTime}+5000]}]
      This:changeNextT[0.250]
    }
  }

  member:bool ValidHP()
  {
    if !${Me.Target(exists)} || ${Me.Target.Type.Equal[Resource]}
      return FALSE
    if !${UIElement[MobsEngagedCombo@CustomMobsFrame@Mobs@CustomTabs@CustomFrame@Custom@EZVGTabs@ezvg].ItemByText[${Me.Target.Name}](exists)} && !${Me.Target.Name.Find[corpse of]} && !${Me.Target.Name.Find[remains of]}
      UIElement[MobsEngagedCombo@CustomMobsFrame@Mobs@CustomTabs@CustomFrame@Custom@EZVGTabs@ezvg]:AddItem[${Me.Target.Name}]  
    if ( ${Me.TargetHealth}<=${EngagePct} || ${This.CommandAssist} ) && ${Me.TargetHealth}>0 && ${Me.Target.IsAttackable} && ( !${Me.Target.IsDead} || ( ${Me.Chunk.DisplayName.Equal[Sands of Sorrow]} && ${Me.TargetHealth}>0 ) )
    {
      ;echo *** ValidHP returning TRUE
      return TRUE
    }
    return FALSE
  }

  member:bool nonDetrAbilCheck()
  {
    if !${This[parent].didAction} && ${This.ValidHP} && ${Pawn[ID, ${TankID}].CombatState}!=0
      return TRUE
    return FALSE
  }
  
  method combatTargets()
  {
    if !${Me.Target(exists)} && ${Me.Encounter.Equal[0]} && ${Pawn[ID, ${Me.ToPawn.ID}].CombatState}!=0 && !${huntPaused}
    {
      VGExecute /cleartargets
      This:changeNextT[0.10]
    }
    elseif ${Me.Encounter}>0 && ( !${Me.Target(exists)} || ( ${Me.Target.Type.Equal[Corpse]} && ${Me.TargetHealth.Equal[0]} ) )
    {
      if ${Me.FName.Equal[${Assist}]}
       This:changeTgt[${Me.Encounter[${This.grabLowHealthTgt}].ToPawn.ID}]
      else
       This:Assist
    }
    elseif ${Me.Target(exists)} && ${This.ValidHP} && ${Me.Encounter}>0
      This:Assist
  }
  
  member:bool shouldIAssist()
  {
    if ( ${doAssist} || ${Assist.Equal[${Me.FName}]} ) && !${This[parent].didAction} && ${This.ValidHP}
    {
      if ${Me.Target.Owner(exists)}
      {
        if ${Group[${Me.Target.Owner.Name.Token[1, " "]}](exists)} || ${Me.Target.OwnedByMe}
          return TRUE
        else
          return FALSE
      }
      else
        return TRUE
    }
    return FALSE  
  }

  member:bool shouldUseAttack()
  {
    ; test to see if tgtFurious is correct
    if !${Me.Target(exists)} 
      return FALSE
    if !${Me.Target.HaveLineOfSightTo} || ( ${Me.Target.Distance}>${moveToTargetDist} && !${Mov.toggleRange} )
      return FALSE
    if ${Script.RunningTime} > ${Math.Calc[${This.tgtFuriousT} + 10000]} && ${This.tgtFurious}
    {
      if !${Me.TargetBuff[Furious](exists)} && !${Me.TargetBuff[Furious Rage](exists)}
        This.tgtFurious:Set[FALSE]
    }
    if ${Me.TargetBuff[Rust Shield](exists)} || ${Me.TargetBuff[Furious Rage](exists)}
      return FALSE
    if !${doIgnoreFurious} && ( ${Me.TargetBuff[Furious](exists)} || ${This.tgtFurious} )
      return FALSE
    if ${Me.TargetBuff[Aura of Death](exists)} || ${Me.TargetBuff[Frightful Aura](exists)}
      return FALSE
    if ${Me.TargetBuff[Major Enchantment: Ulvari Flame](exists)} || ${Me.Effect[Mark of Verbs](exists)}
      return FALSE
    if ${Me.TargetBuff[Major Disease: Fire Advocate](exists)} || ${Me.Effect[Devout Foeman I](exists)} || ${Me.Effect[Devout Foeman II](exists)} || ${Me.Effect[Devout Foeman III](exists)}
      return FALSE
    if ${Me.Target.Type.Equal[Group Member]} || ${Me.Target.Type.Equal[Pet]}
      return FALSE
    return TRUE
  }
  
  member:bool IsAbilReady(string abilName)
  {
    if ${abilName.Length.Equal[0]} || ${abilName.Equal[NULL]}
      return FALSE
    if !${Me.Ability[${abilName}](exists)} && ( ${Me.HavePet} && !${Me.Pet.Ability[${abilName}](exists)} )
      return FALSE
    if !${Me.Ability[${abilName}].IsReady} && ( ${Me.HavePet} && !${Me.Pet.Ability[${abilName}].IsReady} )
      return FALSE
    return TRUE
  }
  
  member:bool IsBurnReady()
  {
    ; first check is should we burn?
    if !${doBurn}
      return FALSE
    ; next check is target health
    if ${Me.TargetHealth}>${burnPct} || ${Me.TargetHealth}<${burnAbovePct}
      return FALSE
    ; next is doBurnAbil and burnAbilTrigger
    if ${doBurnAbil}
    {
      if !${This.IsAbilReady[${burnTrigger}]}
        return FALSE
    }
    ; next is doBurnBuff and burnBuffTrigger
    if ${doBurnBuff}
    {
      if !${This.IsAbilReady[${burnBuffTrigger}]}
        return FALSE
    }
    ; finally we have doBurnBuffExists and burnBuffExistsTrigger
    if ${doBurnBuffExists}
    {
      if !${Me.Effect[${burnBuffExistsTrigger}](exists)}
        return FALSE
    }
    if ${doSpecPtsBurn}
    {
      if !${This.SpecialPointsNeeded[${minSpecPtsBurn}]}
        return FALSE
    }
    return TRUE
  }

  method CheckMyBuffs()
  {
    variable int iterCnt
    for (iterCnt:Set[1] ; ${iterCnt} <= ${Me.Effect.Count} ; iterCnt:Inc)
    {
      if !${UIElement[BurnBuffExistsTrigger@OptionsBurnFrame@Burn@OptionsTabs@OptionsFrame@Options@EZVGTabs@ezvg].ItemByText[${Me.Effect[${iterCnt}].Name}](exists)}
        UIElement[BurnBuffExistsTrigger@OptionsBurnFrame@Burn@OptionsTabs@OptionsFrame@Options@EZVGTabs@ezvg]:AddItem[${Me.Effect[${iterCnt}].Name}]
    }
    This.lastBuffCheckT:Set[${Math.Calc[${Script.RunningTime}+5000]}]
  }
  ;############################################
  ;##
  ;##  THIS SHIT YOU CAN DICK AROUND WITH
  ;##
  ;############################################
  
  method LogicPulse()
  {
    if ${Script.RunningTime}>=${This.nextCheckT}
    {
      if ${Me.ToPawn.IsDead} && ${Me.Health.Equal[0]}
      {
        VGExecute /rezaccept
        This:changeNextT[1.00]
        return
      }
      elseif ${Paused} || ${Me.ToPawn.IsStunned} || !${Me.Ability[Auto Attack].IsReady}
        return
      elseif !${Me.InCombat} && !${Me.Target(exists)} && ${Me.Encounter.Equal[0]}
        return
      elseif ( ${doLoot} || ${doLootOnly} ) && ${Me.IsLooting}
        NonCmbt:LootLogic
      elseif ${Me.IsCasting}
      {
        if ${doReact} && ${Me.TargetCasting.NotEqual[None]} && ${This[parent].RotReady["react"]}
        {
          VGExecute /stopcasting
          This[parent]:WeaponSets[react]
          VGExecute /reactionautocounter
          This:changeNextT[0.125]
        }
        else
          return 
      }
      else
        This:combatLogic
    }
  }

  method combatLogic()
  {
    ;echo --- obj_Combat:combatLogic --- ${Script.RunningTime}
    This[parent].didAction:Set[FALSE]
    This:combatTargets
    if ${Me.Ability[Auto Attack].Toggled} && ( !${This.shouldUseAttack} || ( ${This.tgtFurious} && !${doIgnoreFurious} ) )
      This[parent]:useAutoAtk
    if ${doHeal} || ${doCanni} || ${doCmbtRez}
      This:healCanniRezLogic
    if ( ${doStripEnchantment} || ${doReact} ) && ${This.nonDetrAbilCheck}
    {
      if ${doFace}
        face ${Me.Target.X} ${Me.Target.Y}
      if ${doReact}
        This[parent]:useAbil["react"]
      if ${doStripEnchantment} && !${This[parent].didAction}
        This:StripEnchantmentLogic
    }
    if ${This.shouldIAssist} && ( ${This.shouldUseAttack} || ${doIgnoreFurious} )
    {
      if ${doFace} && !${doStripEnchantment}
        face ${Me.Target.X} ${Me.Target.Y}
      if !${This[parent].petAttacking} && ${Me.HavePet} && ${This.shouldUseAtk}
      {
        VGExecute /pet attack
        This[parent].petAttacking:Set[TRUE]
      }
      if ${Me.InCombat} && ${Me.Class.Equal[Bard]} && ${doCombatSong} && ${Songs[${combatSong}](exists)} && !${Me.Effect[${Me.FName}'s Bard Song - "${combatSong}"](exists)}
        Songs[${combatSong}]:Perform
      ;elseif ${Me.Class.Equal[Ranger]} && ( ${doRange} || ${doRangeDots} ) && ${Math.Calc[${This.meleeFocus} + 120000)]} > ${Script.RunningTime}
      ;  This:changeMeleeFocus[60]
      This:PreAbilityItemUse
      if ${This[parent].inBurn}
      {
        if ${Me.Effect[${burnBuffTrigger}](exists)}
          This[parent]:useAbil["burn"]
        else
          This[parent].inBurn:Set[FALSE]
      }
      if ${This.IsBurnReady}
        This:BurnLogic
      if ${Me.Class.Equal[Bard]}
      {
        if ${doNuke} && ${Me.EnergyPct}>=${enerNukePct}
        {
          if ${Me.Ability[Eaon's Booming Bellow].IsReady} && !${This[parent].WillAbilHealMob["Eaon's Booming Bellow", ${Me.Target.Name}]}
            Me.Ability["Eaon's Booming Bellow"]:Use
          if ${Me.Ability[Eaon's Superior Blasting Bellow].IsReady} && !${This[parent].WillAbilHealMob["Eaon's Superior Blasting Bellow", ${Me.Target.Name}]}
            Me.Ability["Eaon's Superior Blasting Bellow"]:Use
        }
        if ${doDots} && ${Me.EnergyPct}>=${enerDOTPct}
        {
          if ${Me.Ability[Fasant's Chant of Corruption III].IsReady} && ${This[parent].TgtBuffCheck["Fasant's Chant of Corruption III"]} && !${This[parent].WillAbilHealMob["Fasant's Chant of Corruption III", ${Me.Target.Name}]}
            Me.Ability["Fasant's Chant of Corruption III"]:Use
          elseif ${Me.Ability[Fasant's Chant of the Flame III].IsReady} && ${This[parent].TgtBuffCheck["Fasant's Chant of the Flame III"]} && !${This[parent].WillAbilHealMob["Fasant's Chant of the Flame III", ${Me.Target.Name}]}
            Me.Ability["Fasant's Chant of the Flame III"]:Use
          elseif ${Me.Ability[Fasant's Chant of Winter III].IsReady} && ${This[parent].TgtBuffCheck["Fasant's Chant of Winter III"]} && !${This[parent].WillAbilHealMob["Fasant's Chant of Winter III", ${Me.Target.Name}]}
            Me.Ability["Fasant's Chant of Winter III"]:Use
        }
      }
      elseif ${Me.Class.Equal[Druid]} && ${Me.Inventory[Fireseeds](exists)} && !${Me.TargetMyDebuff[Fireseeds}](exists)} && !${This[parent].WillGENAbilHealMob["Fireseeds", ${Me.Target.Name}]}
      {
        Me.Inventory[Fireseeds]:Use
      }
      if ${doEvasive} && ${Me.HealthPct}<=${evasivePct} && !${This[parent].didAction}
        This[parent]:useAbil["evasive"]
      if !${Tank.Equal[${Me.TargetOfTarget}]} && ${doRescue} && !${This[parent].didAction} && ${Me.TargetHealth}<=99
      {
        This[parent]:changeTgt[${Pawn[exactname, ${Me.TargetOfTarget}].ID}]
        This[parent]:useAbil["rescue", ${Pawn[exactname, ${Me.TargetOfTarget}].ID}]
      } 
      if ${doStancePush} && !${This[parent].didAction}
        This:StancePushLogic
      if ${doKillingBlow} && !${This[parent].didAction} && ${Me.TargetHealth}<=${killingBlowPct}
        This[parent]:doUseAbil["${killingBlow}"]
      if ${doCombatBuff} && !${This[parent].didAction} && ( ${Me.FName.NotEqual[${Assist}]} || ${Me.ToPawn.CombatState}!=0 )
        This[parent]:useAbil["combatbuff", ${Me.ToPawn.ID}]
      if ${Me.Encounter}>0 && !${This[parent].didAction}
      {
        if ${doHateOnAdds} && ${Me.Target.TargetOfTarget.Name.Equal[${Me.FName}]} && ${Tank.Equal[${Me.FName}]}
          This:AggroManagement
        if ${doAEHateToTank} && ${Me.TargetHealth} >= ${hateToTankPct}
          This[parent]:useAbil["AEHateToTank", ${TankID}]
        if ( ${doAE} || ( ${Me.Target.Name.Equal[Zyxil]} || ${Me.Encounter[Zyxil](exists)} ) ) && !${This[parent].didAction}
          This:AELogic
      }
      if ${doHateToTank} && ${Me.TargetHealth} >= ${hateToTankPct} && !${This[parent].didAction}
        This[parent]:useAbil["hateToTank", ${TankID}]
      if ${doDTgtDeaggro} && ${Me.TargetHealth} >= ${hateToTankPct} && !${This[parent].didAction}
      {
        if ${Pawn[ID, ${DTgtDeaggroID}](exists)}
        {
          if ${Pawn[ID, ${DTgtDeaggroID}].CombatState}!=0
            This[parent]:useAbil["dtgtdeaggro", ${DTgtDeaggroID}]
        }
        elseif ${Pawn[ID, ${Me.ToPawn.ID}].CombatState}!=0
        {
          ; dtgt deaggros default to self
          This[parent]:useAbil["dtgtdeaggro", ${Me.ToPawn.ID}]
        }
      }
      if ${doSpecPts} && !${This[parent].didAction}
      {
        ;echo obj_Combat:combat logic pulse and we need special points
        if ${This.SpecialPointsNeeded[${minSpecPts}]}
          This[parent]:useAbil["special"]
          
      }
      if ${doMeleeDebuff} && !${This[parent].didAction}
        This[parent]:useAbil["meleedebuff"]
      if ${doRangeDebuff} && !${This[parent].didAction}
        This[parent]:useAbil["rangedebuff"]
      if ${doDebuff} && !${This[parent].didAction}
        This[parent]:useAbil["debuff"]
      if ${doMeleeDots} && !${This[parent].didAction}
        This[parent]:useAbil["meleedot"]
      if ${doRangeDots} && !${This[parent].didAction}
        This[parent]:useAbil["rangedot"]
      if !${Me.Class.Equal[Bard]} && ${doDots} && !${This[parent].didAction} && ${Me.EnergyPct}>=${enerDOTPct}
        This[parent]:useAbil["dot"]
      if ${doPet} && !${This[parent].didAction} && ${doPetInCombat}
        This:PetLogic
      if ${doMelee} && !${This[parent].didAction}
        This[parent]:useAbil["melee"]
      if ${doRange} && !${This[parent].didAction}
        This[parent]:useAbil["range"]
      if !${Me.Class.Equal[Bard]} && ${doNuke} && !${This[parent].didAction} && ${Me.EnergyPct}>=${enerNukePct}
        This[parent]:useAbil["nuke"]
    }
    if ${Script.RunningTime}>${This.lastBuffCheckT}
      This:CheckMyBuffs
    if ${Script.RunningTime}>${This.nextCheckT}
      This:changeNextT[0.125]
  }

  ;+++++++++++++++++++++++++++++++++++++++++++++++++
  ;++
  ;++      BENEFICIAL ABILITY USE
  ;++
  ;+++++++++++++++++++++++++++++++++++++++++++++++++
  method healCanniRezLogic()
  {
    if ${doItemCanni} && ${Me.EnergyPct}<=${canniEnerPct} && ${Me.HealthPct}>=${canniHPPct}
      This[parent]:useItem["canni"]
    if ${doHeal}
      This:HealLogic
    if ${doCanni} && !${This[parent].didAction} && ${Me.EnergyPct}<=${canniEnerPct} && ${Me.HealthPct}>=${canniHPPct}
      This[parent]:useAbil["canni"]
    if ${doCmbtRez} && !${This[parent].didAction}
      This:RezLogic
  }
  
  method HealLogic()
  {
    variable int iterGrpCnt = 1
    variable int grpInRng = 0
    variable int lowGrpMem = 0
    if ${Me.IsGrouped}
    {
      do
      {
        if ${Group[${iterGrpCnt}].ID(exists)}
        {
          if ${doGroupHeal} && ${Group[${iterGrpCnt}].Health}<=${healGrpPct} && ${Group[${iterGrpCnt}].Distance}<=10 && !${Group[${iterGrpCnt}].ToPawn.IsDead}
            grpInRng:Inc[1]
          if ${Group[${iterGrpCnt}].ID}!=${TankID} && ${Group[${iterGrpCnt}].Health}<=${healBigPct} && ${Group[${iterGrpCnt}].Health}>0 && ${Group[${iterGrpCnt}].Distance}<25
          {
            if ${lowGrpMem}==0
              lowGrpMem:Set[${iterGrpCnt}]
            elseif ${Group[${iterGrpCnt}].Health}<${Group[${lowGrpMem}].Health}
              lowGrpMem:Set[${iterGrpCnt}]
          }
        }
        iterGrpCnt:Inc[1]
      }
      while ${Group[${iterGrpCnt}].ID(exists)}
    }
    if ${healGrpMinInRng}<=${grpInRng} && ${doGroupHeal}
      This[parent]:useAbil["healgrp", ${Me.ToPawn.ID}]
    if !${This[parent].didAction} && ${Me.HealthPct}<=${healMedPct}
      This[parent]:useAbil["healmed", ${Me.ToPawn.ID}]
    if !${This[parent].didAction}
    {
      if ${Me.IsGrouped} && ${Group[${Tank}](exists)}
      {
        if ( ${Group[${Tank}].Health}<=${healBigPct} || ( ${Group[${Tank}].Health}<=${healHOTPct} && ${doHOT} )) && ${Pawn[id, ${TankID}](exists)} && !${Pawn[id, ${TankID}].IsDead}
        {
          if ${Group[${Tank}].Health}<=${healEmgPct}
            This[parent]:useAbil["healemg", ${TankID}]
          if ${Group[${Tank}].Health}<=${healBigPct} && !${This[parent].didAction}
            This[parent]:useAbil["healbig", ${TankID}]
          if ${doHOT} && ${Group[${Tank}].Health}<=${healHOTPct} && !${This[parent].didAction}
            This[parent]:useAbil["healhot", ${TankID}]
        }
        if !${This[parent].didAction} && ${Me.IsGrouped} && ${lowGrpMem}>0 && (( ${Group[${lowGrpMem}].Health}<=${healHOTPct} && ${doHOT} ) || ${Group[${lowGrpMem}].Health}<=${healMedPct} )
        {
          if ${Group[${lowGrpMem}].Health}<=${healEmgPct}
            This[parent]:useAbil["healemg", ${Group[${lowGrpMem}].ID}]
          if ${Group[${lowGrpMem}].Health}<=${healMedPct} && !${This[parent].didAction}
            This[parent]:useAbil["healmed", ${Group[${lowGrpMem}].ID}]
          if ${doHOT} && ${Group[${lowGrpMem}].Health}<=${healHOTPct} && !${This[parent].didAction}
            This[parent]:useAbil["healhot", ${Group[${lowGrpMem}].ID}]
        }
      }
      elseif ${Me.DTarget.ID}!=${TankID} && !${Me.IsGrouped} && !${Me.ToPawn.ID.Equal[${TankID}]}
        This:changeTgt[${TankID}]
      ;elseif ${Me.DTarget.ID}!=${TankID} && ${Pawn[AggroNPC].Distance}<=30
      ;  This:changeTgt[${TankID}]
      elseif !${Me.IsGrouped} && ${Me.DTarget.ID.Equal[${TankID}]} && ${Pawn[AggroNPC].Distance}<=30
      {
        if ${Me.DTargetHealth}<=${healEmgPct}
          This[parent]:useAbil["healemg", ${TankID}]
        if ${Me.DTargetHealth}<=${healMedPct} && !${This[parent].didAction}
          This[parent]:useAbil["healmed", ${TankID}]
        if ${Me.DTargetHealth}<=${healBigPct} && !${This[parent].didAction}
          This[parent]:useAbil["healbig", ${TankID}]
        if ${doHOT} && ${Me.DTargetHealth}<=${healHOTPct} && !${This[parent].didAction}
          This[parent]:useAbil["healhot", ${TankID}]
      }
    }
  }

  method GroupBuffLogic()
  {
    variable int grpIter
    grpIter:Set[1]
    do
    {
      if ${Me.FName.Equal[${Group[${grpIter}]}]}
        This[parent]:useAbil["groupbuff", ${Me.ToPawn.ID}]
      else
        This[parent]:useAbil["groupbuff", ${Group[${grpIter}].ID}]
      grpIter:Inc[1]
    }
    while !${This[parent].didAction} && ${Group[${grpIter}](exists)}
  }
  
  method RezLogic()
  {
    if !${Me.Class.Equal[Cleric]} && !${Me.Class.Equal[Disciple]} && !${Me.Class.Equal[Shaman]} && !${Me.Class.Equal[Blood Mage]}
      return
    variable int curGrpMem
    variable int needsRez
    needsRez:Set[0]
    curGrpMem:Set[1]
    do
    { 
      if ${Group[${curGrpMem}].Health}==0 && ${Group[${curGrpMem}].ToPawn.IsDead}
      {
        if ${needsRez.Equal[0]}
          needsRez:Set[${curGrpMem}]
        elseif !${This.GroupMemberHealer[${needsRez}]} && ${This.GroupMemberHealer[${curGrpMem}]}
          needsRez:Set[${curGrpMem}]
      }
      curGrpMem:Inc[1]
    }
    while ${Group[${curGrpMem}](exists)}
    if ${needsRez}>0
    {
      if ${Me.InCombat} && ${Me.Ability[${combatRez}].IsReady}
        This[parent]:doUseAbil[${combatRez}, ${Group[${needsRez}].ID}]
      elseif !${Me.InCombat} && ${Me.Ability[${nonCombatRez}].IsReady}
        This[parent]:doUseAbil[${nonCombatRez}, ${Group[${needsRez}].ID}]
    }
  }

  member:bool GroupMemberHealer(int grpNmbr)
  {
    if ${Group[${grpNmbr}].Class.Equal[Cleric]}
      return TRUE
    if ${Group[${grpNmbr}].Class.Equal[Disciple]}
      return TRUE
    if ${Group[${grpNmbr}].Class.Equal[Shaman]}
      return TRUE
    if ${Group[${grpNmbr}].Class.Equal[Blood Mage]}
      return TRUE
    return FALSE
  }
  ;---------------------------------------------
  ;--
  ;--         DETRIMENTAL ABILITY
  ;--
  ;---------------------------------------------
  method PreAbilityItemUse()
  {
    ; === for item use that doesn't effect GCD
    if ${doItemAssist}
      This[parent]:useItem["assist"]
    if ${doItemTank} && !${This[parent].didAction}
      This[parent]:useItem["tank"]
    if ${doItemOTgt} && !${This[parent].didAction}
      This[parent]:useItem["otgt"]
    if ${doRedBerries} && ${Me.Inventory[Great Roseberries](exists)} && ${Me.HealthPct}<${useRedBerryPct}
    {
      if ${Me.Inventory[Great Roseberries].IsReady}
        Me.Inventory[Great Roseberries]:Use
    }
    elseif ${doBlueBerries} && ${Me.Inventory[Large Mottleberries](exists)} && ${Me.EnergyPct}<${useBlueBerryPct}  
    {
      if ${Me.Inventory[Large Mottleberries].IsReady}
        Me.Inventory[Large Mottleberries]:Use
    }
    if ${This[parent].didAction}
      This[parent].didAction:Set[FALSE]
  }
  
  method AELogic()
  {
    variable int numInRng = 0
    variable int numCurEnc = 0
    do
    {
      if ${Me.Encounter[${numCurEnc}].Distance}<=${AEDist}
        numInRng:Inc[1]
      numCurEnc:Inc[1]
    }
    while ${Me.Encounter[${numCurEnc}](exists)}
    if ${numInRng}>1
      This[parent]:useAbil["AE"]
  }
  
  method AggroManagement()
  {
    ; Called after we know that we have a ValidTgt AND Encounter > 0
    ; Prioritized as follows: Finds the highest difficult and then
    ; will tgt based on 1. caster, 2. healer, 3. melee dps, 4. defensive fighters
    variable int iterCnt
    variable bool haveNewTgt
    variable int newTgtEncNmbr
    haveNewTgt:Set[FALSE]
    iterCnt:Set[1]
    do
    {
      if !${Me.Encounter[${iterCnt}].TargetOfTarget.Name.Equal[${Me.FName}]}
      {
        if !${haveNewTgt}
        {
          ; doing this so don't have to run comparisons all the time
          haveNewTgt:Set[TRUE]
          newTgtEncNmbr:Set[${iterCnt}]
        }
        elseif ${Me.Encounter[${iterCnt}].Difficulty}>${Me.Encounter[${newTgtEncNmbr}].Difficulty}
        {
          ; new mob is more powerful, default new tgt
          newTgtEncNmbr:Set[${iterCnt}]
        }
        elseif ${Me.Encounter[${iterCnt}].Difficulty}>=${Me.Encounter[${newTgtEncNmbr}].Difficulty}
        {
          ; same difficulty, check to see who it is attacking
          ; if the person is not in our group then not fussed about it
          ; because i can't check their class
          if ${Group[${Me.Encounter[${iterCnt}].TargetOfTarget.Name}](exists)}
          {
            if ${This.AggroPriority[${Me.Encounter[${iterCnt}].TargetOfTarget.Name}]} > ${This.AggroPriority[${Me.Encounter[${newTgtEncNmbr}].TargetOfTarget.Name}]}  
              newTgtEncNmbr:Set[${iterCnt}]
          }
        }
      }
      iterCnt:Inc[1]
    }
    while ${Me.Encounter[${iterCnt}](exists)}
    if ${haveNewTgt}
      This:changeTgt[${Me.Encounter[${newTgtEncNmbr}].ID}]
  }
  
  member:bool AggroPriority(string allyName)
  {
    ; aggro priorities are as follows:
    ; 4 = caster
    ; 3 = healer
    ; 2 = melee dps
    ; 1 = tank types
    if !${Group[${allyName}](exists)}
      return 0
    if ${Group[${allyName}].Class.Equal[Druid]} || ${Group[${allyName}].Class.Equal[Sorcerer]} || ${Group[${allyName}].Class.Equal[Necromancer]} ||  ${Group[${allyName}].Class.Equal[Psionicist]}
      return 4
    elseif ${Group[${allyName}].Class.Equal[Shaman]} || ${Group[${allyName}].Class.Equal[Cleric]} || ${Group[${allyName}].Class.Equal[Disciple]} ||  ${Group[${allyName}].Class.Equal[Bloodmage]}
      return 3
    elseif ${Group[${allyName}].Class.Equal[Bard]} || ${Group[${allyName}].Class.Equal[Monk]} || ${Group[${allyName}].Class.Equal[Rogue]} ||  ${Group[${allyName}].Class.Equal[Ranger]}
      return 2
    else
      return 1
  }
  
  method BurnLogic()
  {
    variable iterator abilIter
    This[parent].inBurn:Set[TRUE]
    if ${doBurnItemBuff}
      This[parent]:useItem["burnitem"]
    if ${doBurnConsumableItemBuff}
      This[parent]:useItem["burnconsumeitem"]
    This[parent]:useAbil["burnbuff", ${Me.ToPawn.ID}]
    if ${doBurnEpic} && ${Me.Inventory[${burnEpicName}](exists)}
    {
      if ${Me.Inventory[${burnEpicName}].IsHotkeyed} && ${Me.Inventory[${burnEpicName}].IsReady}
        VGExecute /itemuse \"${burnEpicName}\"
    }
    This[parent]:useAbil["burn", ${Me.ToPawn.ID}]
  }
  
  method WeaknessLogic()
  {
    if ${abilWeaknessDict.FirstKey(exists)}
    {
      do
      {
        if ${Me.TargetWeakness[${abilWeaknessDict.CurrentValue}](exists)}
          This[parent]:doUseAbil[${abilWeaknessDict.CurrentKey}]
      }
      while !${This[parent].didAction} && ${abilWeaknessDict.NextKey(exists)}
    }
  }
  
  method StancePushLogic()
  {
    variable int iterCnt
    variable bool needDisenchant = FALSE
    if ${stancePush.Length.Equal[0]} || !${Me.Ability[${stancePush}](exists)} || ${Me.TargetBuff.Equal[0]}
      return
    if !${Me.Ability[${stancePush}].IsReady}
      return
    for (iterCnt:Set[1] ; ${iterCnt}<=${Me.TargetBuff} ; iterCnt:Inc )
    {
      if ${Me.TargetBuff[${iterCnt}].Name.Find[Stance]}
        needDisenchant:Set[TRUE]
    }
    if ${needDisenchant}
      This[parent]:doUseAbil["${stancePush}"]
  }
  
  method StripEnchantmentLogic()
  {
    variable int iterCnt
    variable bool needDisenchant = FALSE
    if ${stripEchantment.Length.Equal[0]} || !${Me.Ability[${stripEnchantment}](exists)} || ${Me.TargetBuff.Equal[0]}
      return
    if !${Me.Ability[${stripEnchantment}].IsReady}
      return
    for (iterCnt:Set[1] ; ${iterCnt}<=${Me.TargetBuff} ; iterCnt:Inc )
    {
      if ${Me.TargetBuff[${iterCnt}].Name.Find[Enchantment]}
        needDisenchant:Set[TRUE]
    }
    if ${needDisenchant}
      This[parent]:doUseAbil["${stripEnchantment}"]
  }

  ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  ;@@
  ;@@      OTHER LOGIC
  ;@@
  ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  member:bool SpecialPointsNeeded(int specNeed)
  {
    if ${Me.Class.Equal[Monk]} || ${Me.Class.Equal[Disciple]}
    {
      if ${Me.Stat[Adventuring,Jin]}<${specNeed}
        return TRUE
    }
    elseif ${Me.Class.Equal[Druid]}
    {
      if ${Me.Stat[Adventuring,Phenomia Points]}<${specNeed}
        return TRUE
    }
    elseif ${Me.Class.Equal[${Bloodmage}]}
    {
      if ${Me.Stat[Adventuring,Blood Count]}<${specNeed}
        return TRUE
    }
    elseif ${Me.Class.Equal[${Paladin}]}
    {
      if ${Me.Stat[Adventuring,Virtue Points]}<${specNeed}
        return TRUE
    }

    return FALSE
  }

  method changeMeleeFocus(float delta)
  {
    ;This.meleeFocus:Set[${Math.Calc[${Script.RunningTime}+( ${delta} * 1000 )]}]
  }

  member:int grabLowHealthTgt()
  {
    variable int encNmbr
    variable int lowHealth
    encNmbr:Set[1]
    lowHealth:Set[1]
    do
    {
      if !${Me.Encounter[${lowHealth}].ToPawn.IsDead} && ${Me.Encounter[${encNmbr}].Health}<${Me.Encounter[${lowHealth}].Health}
        lowHealth:Set[${encNmbr}]
      encNmbr:Inc[1]
    }
    while ${Me.Encounter[${encNmbr}](exists)}
    return ${lowHealth}
  }
  
}

variable ezvg_Combat Combat